package com.tanxi521.com.thenorthtitle.util;

import com.tanxi521.com.thenorthtitle.TheNorthTitle;
import org.black_ixx.playerpoints.PlayerPoints;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.Plugin;

public class PointApi {
    public static PlayerPoints points = null;

    public static boolean hookPlayerPoints() throws ClassNotFoundException {
        Plugin plugin = TheNorthTitle.getInstance().getServer().getPluginManager().getPlugin("PlayerPoints");
        if (plugin != null)
            if ((points = (PlayerPoints) PlayerPoints.class.cast(plugin)) != null)
                return true;
        return false;
    }

    public static boolean hasPoint(OfflinePlayer player, double minimum) {
        if (points == null) {
            throw new IllegalStateException();
        } else if (minimum < 0.0D) {
            throw new IllegalArgumentException("无效的金额: " + minimum);
        } else {
            return points.getAPI().look(player.getName()) >= minimum;
        }
    }

    public static int getPoints(OfflinePlayer player) {
        return points.getAPI().look(player.getName());
    }

    public static boolean setPoints(OfflinePlayer player, int point) {
        return points.getAPI().set(player.getName(), point);
    }

    public static boolean takePoints(OfflinePlayer player, int point) {
        return points.getAPI().take(player.getName(), point);
    }

    public static boolean givePoints(OfflinePlayer player, int point) {
        return points.getAPI().give(player.getName(), point);
    }

}